from CommonUIImp.CLInstructionSrc import CLInstructionSrc
from CommonUIImp.TextInstructionSrc import TextInstructionSrc
from CommonUIImp.DefaultLogger import DefaultLogger
from CommonUIImp.TextUI import TextUI
from CommonUIImp.InvokeMode import InvokeMode
from .Config import Config
from .UIInstructionImp import *  # 不可删除
from .InvokeInstructionImp import *

g_logger:DefaultLogger = None
g_cfg:Config = None

def Initialization(logger):
    global g_logger
    global g_cfg
    g_logger = logger
    InvokeTUI.SetTUIEntry(TuiMode)
    InvokeTUIBatch.SetTUIEntry(TuiBatchMode)
    g_cfg = Config("config")

def EnterTuiSystem(instSrc):
    tui = TextUI('Welcome to Demo System', instSrc, g_logger, g_cfg)
    tui.MainLoop()

def TuiBatchMode(file):
    instSrc = TextInstructionSrc(file)
    EnterTuiSystem(instSrc)

def TuiMode():
    instSrc = CLInstructionSrc()
    EnterTuiSystem(instSrc)

def EnterInvokeMode(opts):
    opt = opts[0][0][1:]
    args = opts[0][1]
    invokeMode = InvokeMode(g_logger, g_cfg)
    invokeMode.Execute(opt, args)